<template>
    <div id="dialog-container">
        <el-dialog v-dialogDrag 
            title="选择用户" append-to-body
            :visible.sync="dialogVisible" @close="$emit('update:show', false)" :before-close="handleClose" :show="show"
            :close-on-click-modal="false" width="500px">
            <el-table :data="tableData" size="small" border stripe @selection-change="handleSelectionChange">
                <el-table-column type="selection" align="center" :resizable="false" width="55"></el-table-column>
                <el-table-column type="index" label="序号" align="center" :resizable="false" width="50"></el-table-column>
                <el-table-column prop="" label="账户信息" :resizable="false" min-width="90"></el-table-column>
                <el-table-column prop="name" label="真实姓名" :resizable="false" min-width="90"></el-table-column>
            </el-table>
            <el-row type="flex" justify="center">
                <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-sizes="pageSizeArr"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="pageTotal"></el-pagination>
            </el-row>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="ensure">确 定</el-button>
                <el-button @click="dialogVisible = false">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                dialogVisible: this.show,
                tableData: [{
                    id: '001',
                    name: 'zzz'
                },{
                    id: '002',
                    name: 'ccc'
                }],
                multipleSelection: [],
                pageSizeArr: [10, 20, 50],
                pageSize: 10,
                pageTotal: 20,
                currentPage: 1,
            }
        },
        props: {
            show: {
                type: Boolean,
                default: false
            }
        },
        watch: {
            show() {
                this.dialogVisible = this.show;
            }
        },
        methods: {
            handleClose() {
                this.dialogVisible = false;
            },
            handleSizeChange(val){
                // console.log(`每页 ${val} 条`);
            },
            handleCurrentChange(val){
                // console.log(`当前页: ${val}`);
            },
            // 获取表格选择的值
            handleSelectionChange(val) {
                this.multipleSelection = [];
                for(let item in val){
                    this.multipleSelection.push(val[item].name);
                }
            },
            // 确定
            ensure() {
                this.$emit('staffInfo', this.multipleSelection); // 将选择的用户姓名传给父页面
                this.dialogVisible = false;
            }
        }
    }
</script>